package org.example.physics_engine.body;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.physics_engine.Epsilon;
import org.example.physics_engine.geometry.Vector2d;

/*刚体质量*/
@Data
@NoArgsConstructor
public class Mass {

    //质量类型
    private MassType type;
    //质心
    private Vector2d center;
    //质量大小
    private double mass;
    //转动惯量
    private double inertia;
    //质量的倒数
    private double inverseMass;
    //转动惯量倒数
    private double inverseInertia;

    public Mass(Vector2d center, double mass, double inertia) {
        this.type = MassType.NORMAL;
        this.center = center;
        this.mass = mass;
        this.inertia = inertia;
        if (mass > Epsilon.E) {
            this.inverseMass = 1.0/mass;
        } else {
            this.inverseMass = 0.0;
        }
        if (inertia> Epsilon.E) {
            this.inverseInertia = 1.0/inertia;
        } else {
            this.inverseInertia = 0.0;
        }
        //质量和转动惯量为0就是固定住的物体，质量无限大，不可运动
        if (mass <= Epsilon.E && inertia <= Epsilon.E) {
            this.type = MassType.INFINITE;
        }
    }
}
